package pdfsetter.ui;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.pdfbox.pdmodel.PDDocument;

import pdfsetter.core.schema.DocumentSchema;

/**
 * Because compiler receive complete {@link DocumentSchema} and separately list of fils the main program needs to retrieve document sizes on its own. We use
 * method from PDFBox library.
 * 
 * @author Andrzej Dorobisz
 */
public class PDFBasicManager {
    public int[] retrieveDocumentsSizes(List<File> fileList) {
        int[] fileSizes = new int[fileList.size()];
        int i = 0;
        for (File file : fileList) {
            try {
                PDDocument pdd = PDDocument.loadNonSeq(file, null);
                fileSizes[i] = pdd.getNumberOfPages();
                pdd.close();
            } catch (IOException e) {
                return null;
            }
            i++;
        }
        return fileSizes;
    }
}
